<template>
  <div class="app-container" v-loading="loading" :element-loading-text="loadingText">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="挂号单ID" prop="reRrId">
        <el-input
          v-model="queryParams.reRrId"
          placeholder="请输入挂号单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查找</el-button>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">读取IC卡</el-button>
      </el-form-item>
    </el-form>

    <div>
      <el-card style="margin-bottom: 5px">
        <el-form label-position="right" label-width="120px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="挂号单号:">
                <span v-text="careHistory.reRrId"></span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="医生姓名:">
                <span v-text="careHistory.registration.rrDoctor"></span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="科室名称:">
                <span v-text="careHistory.registration.rrDeptName"></span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="患者姓名:">
                <span v-text="careHistory.rePatientPhone"></span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="就诊时间:">
                <span v-text="careHistory.registration.rrDate"></span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主诉:">
                <span v-text="careHistory.reDisSpeak"></span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="诊断信息:">
                <span v-text="careHistory.reDisInfo"></span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="医生建议:">
                <span v-text="careHistory.reDisAdvice"></span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <!-- 病例信息结束 -->
      <!-- 工具按钮开始 -->
      <el-card style="margin-bottom: 5px">
        <el-button type="success" icon="el-icon-finished" @click="handleSelectAll">全选</el-button>
        <el-button type="success" icon="el-icon-finished" @click="handleUnSelectAll">取消全选</el-button>
        <el-button type="danger" icon="el-icon-bank-card" @click="handlePayWithCash">现金支付</el-button>
        <el-button type="danger" icon="el-icon-bank-card" @click="handlePayWithZfb">支付宝支付</el-button>
        <span style="margin-left:20px">订单总额:<span style="color:red;margin-left:20px">￥:{{ amountt }}</span></span>
      </el-card>

      <!-- 工具结束开始 -->
      <!-- 未支付的处方信息开始 -->
      <el-card style="margin-bottom: 5px">
        <!--<el-table
          ref="refTable"
          v-loading="loading"
          :data="careOrders"
          row-key="rdId"
        >

          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" prop="rdId" width="50" />
          <el-table-column label="药品名称" align="center" prop="rdName" />
          <el-table-column label="数量" align="center" prop="rdNum" />
          <el-table-column label="单价(元)" align="center" prop="rdPrice" />
          <el-table-column label="金额(元)" align="center" prop="rdAmount" />
          <el-table-column label="备注" align="center" prop="rdRemark" />
          <el-table-column label="状态" align="center" prop="rdStatus" />
        </el-table>

        <el-table
          v-loading="loading"
          :data="careChecks"
          row-key="rcId"
        >

          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" prop="rcId" width="50" />
          <el-table-column label="检查名称" align="center" prop="rcName" />
          <el-table-column label="单位" align="center" prop="rcDept" />
          <el-table-column label="单价(元)" align="center" prop="rcPrice" />
          <el-table-column label="金额(元)" align="center" prop="rcAmount" />
          <el-table-column label="备注" align="center" prop="rcRemark" />
          <el-table-column label="状态" align="center" prop="rcStatus" />
        </el-table>-->
        <el-collapse v-model="activeNames" @change="handleChange">
          <el-collapse-item  name="1">
            <template slot="title">
              【药用处方】【处方总额】:￥{{amountt}}
            </template>
            <el-table
              ref="refTable"
              v-loading="loading"
              :data="careOrders"
              row-key="rdId"
            >
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" align="center"  type="index" width="50" />
              <el-table-column label="药品名称" align="center" prop="rdName" />
              <el-table-column label="数量" align="center" prop="rdNum" />
              <el-table-column label="单价(元)" align="center" prop="rdPrice" />
              <el-table-column label="金额(元)" align="center" prop="rdAmount" />
              <el-table-column label="备注" align="center" prop="rdRemark" />
              <el-table-column label="状态" align="center" prop="rdStatus" />
            </el-table>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="activeNames" @change="handleChange">
          <el-collapse-item title="检查" name="2" >
            <template slot="title">
              【检查处方】【处方总额】:￥{{amountt}}
            </template>
            <el-table
              ref="refTable"
              v-loading="loading"
              :data="careChecks"
              row-key="rcId"
            >
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" align="center" type="index" width="50" />
              <el-table-column label="检查名称" align="center" prop="rcName" />
              <el-table-column label="单位" align="center" prop="rcDept" />
              <el-table-column label="单价(元)" align="center" prop="rcPrice" />
              <el-table-column label="金额(元)" align="center" prop="rcAmount" />
              <el-table-column label="备注" align="center" prop="rcRemark" />
              <el-table-column label="状态" align="center" prop="rcStatus" />
            </el-table>
          </el-collapse-item>
        </el-collapse>

      </el-card>
      <!-- 未支付的处方信息结束 -->
      <!-- 挂号输入框下面的所有内容结束 -->
    </div>

    <!-- 支付对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="上级菜单">
              <treeselect
                v-model="form.parentId"
                :options="menuOptions"
                :normalizer="normalizer"
                :show-count="true"
                placeholder="选择上级菜单"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="菜单类型" prop="menuType">
              <el-radio-group v-model="form.menuType">
                <el-radio label="M">目录</el-radio>
                <el-radio label="C">菜单</el-radio>
                <el-radio label="F">按钮</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item v-if="form.menuType != 'F'" label="菜单图标">
              <el-popover
                placement="bottom-start"
                width="460"
                trigger="click"
                @show="$refs['iconSelect'].reset()"
              >
                <IconSelect ref="iconSelect" @selected="selected" />
                <el-input slot="reference" v-model="form.icon" placeholder="点击选择图标" readonly>
                  <svg-icon
                    v-if="form.icon"
                    slot="prefix"
                    :icon-class="form.icon"
                    class="el-input__icon"
                    style="height: 32px;width: 16px;"
                  />
                  <i v-else slot="prefix" class="el-icon-search el-input__icon" />
                </el-input>
              </el-popover>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="菜单名称" prop="menuName">
              <el-input v-model="form.menuName" placeholder="请输入菜单名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType != 'F'" label="是否外链">
              <el-radio-group v-model="form.isFrame">
                <el-radio label="0">是</el-radio>
                <el-radio label="1">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType != 'F'" label="路由地址" prop="path">
              <el-input v-model="form.path" placeholder="请输入路由地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.menuType == 'C'">
            <el-form-item label="组件路径" prop="component">
              <el-input v-model="form.component" placeholder="请输入组件路径" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType != 'M'" label="权限标识">
              <el-input v-model="form.perms" placeholder="请权限标识" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType != 'F'" label="显示状态">
              <el-radio-group v-model="form.visible">
                <el-radio
                  v-for="dict in visibleOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType != 'F'" label="菜单状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-if="form.menuType == 'C'" label="是否缓存">
              <el-radio-group v-model="form.isCache">
                <el-radio label="0">缓存</el-radio>
                <el-radio label="1">不缓存</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
    <el-dialog
      title="请使用支付宝支付"
      :visible.sync="openPay"
      center
      :close-on-click-modal="false"
      :before-close="handleClose"
      append-to-body
    >
      <el-form label-position="left" label-width="120px" inline class="demo-table-expand">
        <el-card>
          <el-form-item label="订单号:">
            <span>{{ orderId }}</span>
          </el-form-item>
          <el-form-item label="总金额:">
            <span>{{ amountt }}</span>
          </el-form-item>
        </el-card>
      </el-form>
      <div style="text-align:center">
        <vue-qr :text="payObj.payUrl" :size="200" />
        <div>请使用支付宝扫码</div>
      </div>
    </el-dialog>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
//import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
import { listOrder } from "@/api/charge/pcharge/pcharge";

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";

export default {
  data() {
    return {
        isIndeterminate:false,//对el-checkbox控制不完整的全选状态
        checkAll:false,//对el-checkbox控制全选状态
        //折叠面板
        activeNames: ['1'],
        amountt: 0.00,
        // 支付对象
        payObj: {},
        // 是否打开支付宝二维码支付层
        openPay: false,
        orderId: undefined,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 菜单表格树数据
      menuList: [],

        //设置
        loadingText:'',

        // 病例对象
        careHistory: {
            rePatientPhone:undefined,
            reDisSpeak:undefined,
            reDisInfo:undefined,
            reDisAdvice:undefined,
            registration: {
                rrDoctor:undefined,
                rrDeptName:undefined,
                rrDate:undefined
            }
        },
        // 处方信息
        careOrders: {
          roId:undefined,
            rdName:undefined,
            rdNum:undefined,
            rdPrice:undefined,
            rdAmount:undefined,
            rdRemark:undefined,
            rdStatus:undefined
        },
        //检查单对象
        careChecks: {
            rcId:undefined,
            rcName:undefined,
            rcDept:undefined,
            rcPrice:undefined,
            rcAmount:undefined,
            rcRemark:undefined,
            rcStatus:undefined
        },
      // 菜单树选项
      menuOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 显示状态数据字典
      visibleOptions: [],
      // 菜单状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        roId:undefined,
        menuName: undefined,
        visible: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
          roId: [
              { required: true, message: "不能为空", trigger: "blur" }
          ],
        menuName: [
          { required: true, message: "菜单名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "菜单顺序不能为空", trigger: "blur" }
        ],
        path: [
          { required: true, message: "路由地址不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
     // this.getList();
    this.getDicts("sys_show_hide").then(response => {
      this.visibleOptions = response.data;
    });
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询未缴费列表 */
    getList() {
        this.loading = true;
        this.careHistory = [];
        this.careOrders = [];
      listOrder(this.queryParams).then(response => {
          this.careHistory = response.data.regDisease;
          this.careOrders = response.data.drug;
          this.careChecks = response.data.checks;
          if(this.careHistory==null){
              alert("请输入正确的");
          }
        // this.menuList = this.handleTree(response.data, "menuId");
        this.loading = false;
      });
    },
      //折叠
      handleChange(val) {
        console.log(val)
      },
      handlePayWithZfb() {
        this.loading = true;
        this.$confirm('是否确定创建订单并使用支付宝支付?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
        });
        this.orderId =  this.getOrderId();
        this.openPay = true;
      },

      getOrderId() {
          const tag = 'OD';
          const projectTime = new Date(); // 当前中国标准时间
          const Year = projectTime.getFullYear() ;// 获取当前年份 支持IE和火狐浏览器.
          const Month = projectTime.getMonth() + 1; // 获取中国区月份
          const Day = projectTime.getDate(); // 获取几号
          var CurrentDate = Year;
          if (Month >= 10) { // 判断月份和几号是否大于10或者小于10
              CurrentDate += Month
          } else {
              CurrentDate += '0' + Month
          }
          if (Day >= 10) {
              CurrentDate += Day
          } else {
              CurrentDate += '0' + Day
          }
          const orderID = tag+CurrentDate+Math.floor(Math.random() * 10000);
          return orderID;
      },

































    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.menuId,
        label: node.menuName,
        children: node.children
      };
    },
    /** 查询菜单下拉树结构 */
    getTreeselect() {
      listMenu().then(response => {
        this.menuOptions = [];
        const menu = { menuId: 0, menuName: '主类目', children: [] };
        menu.children = this.handleTree(response.data, "menuId");
        this.menuOptions.push(menu);
      });
    },
    // 显示状态字典翻译
    visibleFormat(row, column) {
      if (row.menuType == "F") {
        return "";
      }
      return this.selectDictLabel(this.visibleOptions, row.visible);
    },
    // 菜单状态字典翻译
    statusFormat(row, column) {
      if (row.menuType == "F") {
        return "";
      }
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.menuId) {
        this.form.parentId = row.menuId;
      } else {
        this.form.parentId = 0;
      }
      this.open = true;
      this.title = "添加菜单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      getMenu(row.menuId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改菜单";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.menuId != undefined) {
            updateMenu(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMenu(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除名称为"' + row.menuName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMenu(row.menuId);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    }
  }
};
</script>
